package com.example.rbacmanage.controller.system;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.system.Notice;
import com.example.rbacmanage.service.system.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/notice")
public class NoticeController{
    @Autowired
    private NoticeService noticeService;
    @GetMapping("/page")
    public Result page(Notice notice){
        return Result.success(noticeService.getPage(notice));
    }

    @GetMapping("/list")
    public Result list(Notice notice){
        return Result.success(noticeService.getAll(notice));
    }

    @GetMapping("/{id}")
    public Result info(@PathVariable Long id){
        return Result.success(noticeService.getById(id));
    }

    @PreAuthorize("hasAnyAuthority('system:notice:add')")
    @PostMapping("/save")
    public Result save(@RequestBody Notice notice){
        noticeService.save(notice);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('system:notice:update')")
    @PutMapping("/update")
    public Result update(@RequestBody Notice notice){
        noticeService.update(notice);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('system:notice:remove')")
    @DeleteMapping("/remove")
    public Result remove(@RequestBody Long[] ids){
        noticeService.remove(ids);
        return Result.success();
    }
}
